package tasky.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;

/**
 * This Class designs a graphic button for Tasky use. This class
 * controls the width and height of the button, as well as
 * graphical effects when rolled over and pressed
 * 
 * @author Keith Lim Yong Ming A0097846J
 *
 */

public class TaskyButton extends JButton {

	private static final long serialVersionUID = 1L;
	
	private Color hoverBackgroundColor;
	private Color pressedBackgroundColor;
	
	private static final int BUTTON_WIDTH = 50;
	private static final int BUTTON_HEIGHT = 25;
	private static final int BUTTON_DEFAULTX = 0;
	private static final int BUTTON_DEFAULTY = 0;
	
	
	private static final boolean DEFAULT_FILLED = false;

	public TaskyButton() {
		this(null);
	}

	public TaskyButton(String text) {
		super(text);
		super.setContentAreaFilled(DEFAULT_FILLED);
	}

	@Override
	protected void paintComponent(Graphics g) {
		if (getModel().isPressed()) {
			g.setColor(pressedBackgroundColor);
		} else if (getModel().isRollover()) {
			g.setColor(hoverBackgroundColor);
		} else {
			g.setColor(getBackground());
		}
		g.fillRect(BUTTON_DEFAULTX, BUTTON_DEFAULTY, getWidth(), getHeight());
		super.paintComponent(g);
	}

	@Override
	public void setContentAreaFilled(boolean b) {
	}
	
	@Override
	public Dimension getPreferredSize() {
	    return new Dimension(BUTTON_WIDTH,BUTTON_HEIGHT);
	}

	public Color getHoverBackgroundColor() {
		return hoverBackgroundColor;
	}

	public void setHoverBackgroundColor(Color hoverBackgroundColor) {
		this.hoverBackgroundColor = hoverBackgroundColor;
	}

	public Color getPressedBackgroundColor() {
		return pressedBackgroundColor;
	}

	public void setPressedBackgroundColor(Color pressedBackgroundColor) {
		this.pressedBackgroundColor = pressedBackgroundColor;
	}
}
